<%@ LANGUAGE=VBScript %>
<%
Option Explicit
%>

<HTML>
<HEAD>
<TITLE ID='L_ExprSel_DialogTitle'>Choose an Expression</TITLE>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=windows-1252'>
<LINK REL='stylesheet' TYPE='text/css' HREF='/widgets/bizdesk.css' ID='mainstylesheet'>

<%
  'Must create this XML island on server
  Response.Write "<XML ID='xmlisExprList'></XML>"
%>

<SCRIPT LANGUAGE='VBScript'>
Option Explicit 

Dim xmlSelected
Dim xmlCancel
Dim m_strHelpTopic         ' Help Topic URL
Dim winHelpWindow          ' Window name used to display help
Set xmlSelected = Nothing
Set xmlCancel = xmlisExprList.xmlDocument.createElement("CANCEL")
Set window.returnValue = xmlCancel

Sub initExprList()
  ' Get the expression-list from the dialog arguments, and plop it into the
  ' page.
  Dim xmlExprList
  Dim objArgs
  Dim btnhelp
  
  Set objArgs = window.dialogArguments

  Set xmlExprList = objArgs.Item("ExprList")

  ' Only display help button if there is a topic
  m_strHelpTopic = objArgs.Item("HelpTopic")
  If IsNull(m_strHelpTopic) Then
    ' Hide the help button
    Set btnhelp = L_Help_Button
    btnHelp.style.display = "none"
  End If
 
  xmlisExprList.loadXML(xmlExprList.xml)
  
  ' Make things look pretty.
  Call onWndResize()
End Sub

Sub onBtnOK()
  Set window.returnValue = xmlSelected
  window.close
End Sub

Sub onBtnCancel()
  window.close
End Sub

Sub onWndResize()
  tblHeader.style.width = divExprList.clientWidth
End Sub

Sub onSelectChange()
  Dim jsrgItems
  Dim trItem
  Dim i
  Dim elButton
  
  Set elButton = L_OK_Button
  jsrgItems = tblExprList.GetSelectedItems()
  If UBound(jsrgItems) = 0 Then
    ' An item is selected.

    ' This is a cheap trick To get the item out of the JScript Array object.
    For i = 0 To UBound(jsrgItems)
      Set trItem = jsrgItems(i)
      ' Get the corresponding XML node.
      Set xmlSelected = xmlisExprList.XMLDocument.selectSingleNode( _
        "EXPRINFOLIST/EXPRINFO[NAME!value() $eq$ '" & _
        trItem.all("spnExprName").innerText & "']")
    Next
    
    elButton.disabled = False
  Else
    ' No items selected now.
    xmlSelected = Null
    elButton.disabled = True
  End If
End Sub

Sub onBtnHelp()
  If Not IsNull(m_strHelpTopic) Then
		If typename(winHelpWindow) = "HTMLWindow2" Then winHelpWindow.close
		Set winHelpWindow = window.open(m_strHelpTopic, "winHelpWindow", _
 					 "height=500,width=700,status=no,toolbar=yes,menubar:no,resizable=yes")
   End If
End Sub
</SCRIPT>

</HEAD>
<BODY onload='initExprList' STYLE="margin:0px;padding:10px">

<DIV STYLE='padding-bottom:4px'>
<LABEL ID='L_ExprSel_StaticText' For='divExprList'>Choose an expression from the list:</LABEL>
</DIV>

<DIV CLASS='clsQueryBldr' STYLE='padding:0px'>
  <TABLE ID='tblHeader' CELLPADDING=0 CELLSPACING=0 
    STYLE='width:100%;margin:0px;padding:0px;table-layout:fixed'>
    <TR>
      <TD ID='L_NameList_Text' STYLE='border:thin outset;width:35%'>Name</TD>
      <TD ID='L_DescList_Text' STYLE='border:thin outset;width:65%'>Description</TD>
    </TR>
  </TABLE>
  <DIV ID='divExprList' ALIGN='center' STYLE='height:200px;overflow-y:scroll'
    LANGUAGE='VBScript' onresize='onWndResize'>
    <TABLE ID='tblExprList' onselectchange='onSelectChange'
      CELLPADDING=0 CELLSPACING=0 DATASRC='#xmlisExprList'
      STYLE='width:100%;behavior:url(/widgets/exprbldrhtc/TableList.htc)'>
      <TR VALIGN='top'>
        <TD STYLE='width:150px'><SPAN ID='spnExprName' DATAFLD='NAME'></SPAN></TD>
        <TD><SPAN DATAFLD='DESC'></SPAN></TD>
      </TR>
    </TABLE>
  </DIV>
</DIV>

<DIV ALIGN='right' STYLE='padding-top:10px'>
  <BUTTON ID='L_OK_Button' DISABLED STYLE='width:60px' onclick='onBtnOK'>OK</BUTTON>
  <SPAN STYLE='width:2px; margin:0px; padding:0px'></SPAN>
  <BUTTON ID='L_Cancel_Button' STYLE='width:60px'onclick='onBtnCancel'>Cancel</BUTTON>
  <SPAN STYLE='width:2px; margin:0px; padding:0px'></SPAN>
  <BUTTON ID='L_Help_Button' STYLE='width:60px'onclick='onBtnHelp'>Help</BUTTON>
</DIV>

</BODY>
</HTML>
